<template>
  <div class="resume-generator">
    <div class="header">
      <h1><i class="fas fa-file-alt"></i> 简历生成器</h1>
      <p class="subtitle">打造专业精美的个人简历</p>
    </div>
    
    <div class="container">
      <!-- 输入表单 -->
      <div class="form-section">
        <div class="form-header">
          <h2><i class="icon fas fa-edit"></i> 填写个人信息</h2>
          <button type="button" @click="getResumeRecord" class="generate-btn">
            <i class="fas fa-history"></i> 获取过往记录
          </button>
        </div>
        
        <form @submit.prevent="generateResume">
          <!-- 基本信息 -->
          <div class="form-group card">
            <div class="form-group-header">
              <i class="fas fa-user"></i>
              <h3>基本信息</h3>
            </div>
            <div class="form-content">
              <div class="form-row">
                <label for="photo">个人照片</label>
                <div class="photo-upload">
                  <input 
                    type="file" 
                    id="photo" 
                    accept="image/*" 
                    @change="handlePhotoUpload"
                    class="photo-input"
                  >
                  <label for="photo" class="upload-btn">
                    <i class="fas fa-camera"></i> 上传照片
                  </label>
                  <div class="photo-preview" v-if="url">
                    <img :src="url" alt="个人照片">
                    <button type="button" class="remove-photo" @click="removePhoto">
                      <i class="fas fa-times"></i>
                    </button>
                  </div>
                </div>
              </div>
              <div class="form-row">
                <label for="name">姓名 <span class="required">*</span></label>
                <input type="text" id="name" v-model="resumeData.name" required placeholder="请输入姓名">
              </div>
              <div class="form-row">
                <label for="job">求职意向 <span class="required">*</span></label>
                <input type="text" id="job" v-model="resumeData.jobTarget" required placeholder="例如：前端开发">
              </div>
              <div class="form-row">
                <label for="phone">电话 <span class="required">*</span></label>
                <input type="tel" id="phone" v-model="resumeData.phone" required placeholder="联系电话">
              </div>
              <div class="form-row">
                <label for="email">邮箱 <span class="required">*</span></label>
                <input type="email" id="email" v-model="resumeData.email" required placeholder="电子邮箱">
              </div>
              <div class="form-row">
                <label for="address">地址</label>
                <input type="text" id="address" v-model="resumeData.address" placeholder="居住地址">
              </div>
            </div>
          </div>
          
          <!-- 教育背景 -->
          <div class="form-group card">
            <div class="form-group-header">
              <i class="fas fa-graduation-cap"></i>
              <h3>教育背景</h3>
            </div>
            <div class="form-content">
              <div v-for="(edu, index) in resumeData.education" :key="index" class="education-item nested-card">
                <div class="form-row">
                  <label :for="'school'+index">学校 <span class="required">*</span></label>
                  <input type="text" :id="'school'+index" v-model="edu.school" required placeholder="学校名称">
                </div>
                <div class="form-row">
                  <label :for="'degree'+index">学历 <span class="required">*</span></label>
                  <input type="text" :id="'degree'+index" v-model="edu.degree" required placeholder="学历">
                </div>
                <div class="form-row">
                  <label :for="'major'+index">专业 <span class="required">*</span></label>
                  <input type="text" :id="'major'+index" v-model="edu.major" required placeholder="专业">
                </div>
                <div class="form-row">
                  <label :for="'period'+index">时间 <span class="required">*</span></label>
                  <input type="text" :id="'period'+index" v-model="edu.period" required placeholder="时间段">
                </div>
                <button type="button" @click="removeEducation(index)" class="remove-btn">
                  <i class="fas fa-trash"></i> 删除
                </button>
              </div>
              <button type="button" @click="addEducation" class="add-btn">
                <i class="fas fa-plus"></i> 添加教育经历
              </button>
            </div>
          </div>
          
          <!-- 工作经历 -->
          <div class="form-group card">
            <div class="form-group-header">
              <i class="fas fa-briefcase"></i>
              <h3>工作经历</h3>
            </div>
            <div class="form-content">
              <div v-for="(exp, index) in resumeData.experience" :key="index" class="experience-item nested-card">
                <div class="form-row">
                  <label :for="'company'+index">公司 <span class="required">*</span></label>
                  <input type="text" :id="'company'+index" v-model="exp.company" required placeholder="公司名称">
                </div>
                <div class="form-row">
                  <label :for="'position'+index">职位 <span class="required">*</span></label>
                  <input type="text" :id="'position'+index" v-model="exp.position" required placeholder="职位">
                </div>
                <div class="form-row">
                  <label :for="'workPeriod'+index">时间 <span class="required">*</span></label>
                  <input type="text" :id="'workPeriod'+index" v-model="exp.period" required placeholder="时间段">
                </div>
                <div class="form-row">
                  <label :for="'workDesc'+index">工作内容 <span class="required">*</span></label>
                  <textarea :id="'workDesc'+index" v-model="exp.description" required placeholder="描述工作职责和成就"></textarea>
                </div>
                <button type="button" @click="removeExperience(index)" class="remove-btn">
                  <i class="fas fa-trash"></i> 删除
                </button>
              </div>
              <button type="button" @click="addExperience" class="add-btn">
                <i class="fas fa-plus"></i> 添加工作经历
              </button>
            </div>
          </div>
          
          <!-- 技能 -->
          <div class="form-group card">
            <div class="form-group-header">
              <i class="fas fa-code"></i>
              <h3>专业技能</h3>
            </div>
            <div class="form-content">
              <div v-for="(skill, index) in resumeData.skills" :key="index" class="skill-item nested-card">
                <div class="form-row">
                  <label :for="'skillName'+index">技能名称 <span class="required">*</span></label>
                  <input type="text" :id="'skillName'+index" v-model="skill.name" required placeholder="技能名称">
                </div>
                <div class="form-row">
                  <label :for="'skillLevel'+index">熟练程度 <span class="required">*</span></label>
                  <div class="select-wrapper">
                    <select :id="'skillLevel'+index" v-model="skill.level" required>
                      <option value="精通">精通</option>
                      <option value="熟练">熟练</option>
                      <option value="了解">了解</option>
                    </select>
                    <i class="fas fa-chevron-down"></i>
                  </div>
                </div>
                <button type="button" @click="removeSkill(index)" class="remove-btn">
                  <i class="fas fa-trash"></i> 删除
                </button>
              </div>
              <button type="button" @click="addSkill" class="add-btn">
                <i class="fas fa-plus"></i> 添加技能
              </button>
            </div>
          </div>
          
          <!-- 项目经历 -->
          <div class="form-group card">
            <div class="form-group-header">
              <i class="fas fa-project-diagram"></i>
              <h3>项目经历</h3>
            </div>
            <div class="form-content">
              <div v-for="(project, index) in resumeData.projects" :key="index" class="project-item nested-card">
                <div class="form-row">
                  <label :for="'projectName'+index">项目名称 <span class="required">*</span></label>
                  <input type="text" :id="'projectName'+index" v-model="project.name" required placeholder="项目名称">
                </div>
                <div class="form-row">
                  <label :for="'projectRole'+index">担任角色 <span class="required">*</span></label>
                  <input type="text" :id="'projectRole'+index" v-model="project.role" required placeholder="担任角色">
                </div>
                <div class="form-row">
                  <label :for="'projectPeriod'+index">项目时间 <span class="required">*</span></label>
                  <input type="text" :id="'projectPeriod'+index" v-model="project.period" required placeholder="时间段">
                </div>
                <div class="form-row">
                  <label :for="'projectDesc'+index">项目描述 <span class="required">*</span></label>
                  <textarea :id="'projectDesc'+index" v-model="project.description" required placeholder="描述项目内容和贡献"></textarea>
                </div>
                <button type="button" @click="removeProject(index)" class="remove-btn">
                  <i class="fas fa-trash"></i> 删除
                </button>
              </div>
              <button type="button" @click="addProject" class="add-btn">
                <i class="fas fa-plus"></i> 添加项目
              </button>
            </div>
          </div>
          
          <div class="actions">
            <button type="button" @click="resetForm" class="reset-btn">
              <i class="fas fa-redo"></i> 重置
            </button>
            <button type="submit" class="generate-btn">
              <i class="fas fa-sync-alt"></i> 更新预览
            </button>
            <button type="button" @click="saveResume" class="generate-btn">
              <i class="fas fa-save"></i> 保存
            </button>
          </div>
        </form>
      </div>
      
      <!-- 简历预览 -->
      <div class="preview-section">
        <div class="preview-header">
          <h2><i class="icon fas fa-eye"></i> 简历预览</h2>
          <div class="preview-actions">
            <button @click="downloadResume" class="download-btn">
              <i class="fas fa-download"></i> 下载
            </button>
            <button @click="printResume" class="print-btn">
              <i class="fas fa-print"></i> 打印
            </button>
          </div>
        </div>
        <div class="resume-preview card">
          <div class="resume-header">
            <div class="name-title">
              <h1>{{ resumeData.name || '姓名' }}</h1>
              <p class="job-target">{{ resumeData.jobTarget || '求职意向' }}</p>
            </div>
            <div class="photo-container" v-if="resumeData.photo">
              <img :src="resumeData.photo" alt="个人照片">
            </div>
          </div>
          
          <div class="resume-body">
            <!-- 基本信息 -->
            <div class="resume-section">
              <div class="section-header">
                <i class="fas fa-info-circle"></i>
                <h2>基本信息</h2>
              </div>
              <div class="info-grid">
                <div v-if="resumeData.phone" class="info-item">
                  <i class="fas fa-phone"></i>
                  <span>{{ resumeData.phone }}</span>
                </div>
                <div v-if="resumeData.email" class="info-item">
                  <i class="fas fa-envelope"></i>
                  <span>{{ resumeData.email }}</span>
                </div>
                <div v-if="resumeData.address" class="info-item">
                  <i class="fas fa-map-marker-alt"></i>
                  <span>{{ resumeData.address }}</span>
                </div>
              </div>
            </div>
            
            <!-- 教育背景 -->
            <div class="resume-section" v-if="resumeData.education.length > 0">
              <div class="section-header">
                <i class="fas fa-graduation-cap"></i>
                <h2>教育背景</h2>
              </div>
              <div class="education-list">
                <div v-for="(edu, index) in resumeData.education" :key="index" class="education-item">
                  <div class="edu-header">
                    <div class="edu-left">
                      <h3>{{ edu.school || '学校名称' }}</h3>
                      <p class="degree-major">{{ edu.degree || '学历' }} | {{ edu.major || '专业' }}</p>
                    </div>
                    <span class="period">{{ edu.period || '时间段' }}</span>
                  </div>
                </div>
              </div>
            </div>
            
            <!-- 工作经历 -->
            <div class="resume-section" v-if="resumeData.experience.length > 0">
              <div class="section-header">
                <i class="fas fa-briefcase"></i>
                <h2>工作经历</h2>
              </div>
              <div class="experience-list">
                <div v-for="(exp, index) in resumeData.experience" :key="index" class="experience-item">
                  <div class="exp-header">
                    <div class="exp-left">
                      <h3>{{ exp.company || '公司名称' }}</h3>
                      <p class="position">{{ exp.position || '职位' }}</p>
                    </div>
                    <span class="period">{{ exp.period || '时间段' }}</span>
                  </div>
                  <div class="description" v-html="formatDescription(exp.description)"></div>
                </div>
              </div>
            </div>
            
            <!-- 技能 -->
            <div class="resume-section" v-if="resumeData.skills.length > 0">
              <div class="section-header">
                <i class="fas fa-code"></i>
                <h2>专业技能</h2>
              </div>
              <div class="skill-list">
                <div v-for="(skill, index) in resumeData.skills" :key="index" class="skill-item">
                  <div class="skill-name">{{ skill.name || '技能名称' }}</div>
                  <div class="skill-level">
                    <div class="level-bar" :style="{width: getSkillLevelWidth(skill.level)}"></div>
                  </div>
                  <div class="level-text">{{ skill.level || '熟练度' }}</div>
                </div>
              </div>
            </div>
            
            <!-- 项目经历 -->
            <div class="resume-section" v-if="resumeData.projects.length > 0">
              <div class="section-header">
                <i class="fas fa-project-diagram"></i>
                <h2>项目经历</h2>
              </div>
              <div class="project-list">
                <div v-for="(project, index) in resumeData.projects" :key="index" class="project-item">
                  <div class="project-header">
                    <div class="project-left">
                      <h3>{{ project.name || '项目名称' }}</h3>
                      <p class="role">担任角色: {{ project.role || '角色' }}</p>
                    </div>
                    <span class="period">{{ project.period || '时间段' }}</span>
                  </div>
                  <div class="description" v-html="formatDescription(project.description)"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import html2canvas from 'html2canvas'
import { ElMessage } from 'element-plus'
import axios from 'axios'
import { post, get } from '@/axios'
import { getFile } from '@/utils'
// 请求拦截器，添加token等认证信息

const url = ref()
const resumeData = ref({
	file: null,
	name: '',
	jobTarget: '',
	phone: '',
	email: '',
	address: '',
	education: [
		{ school: '', degree: '', major: '', period: '' }
	],
	experience: [
		{ company: '', position: '', period: '', description: '' }
	],
	skills: [
		{ name: '', level: '熟练' }
	],
	projects: [
		{ name: '', role: '', period: '', description: '' }
	]
});

// 保存简历到后端
const saveResume = async () => {
	try {
		// 验证必填字段
		if (!resumeData.value.name || !resumeData.value.jobTarget || 
				!resumeData.value.phone || !resumeData.value.email) {
			ElMessage.warning('请填写必填字段（姓名、求职意向、电话、邮箱）');
			return;
		}

		// 准备请求数据，将数组转换为JSON字符串
		const requestData = {
			file: resumeData.value.file || null,
			name: resumeData.value.name,
			jobTarget: resumeData.value.jobTarget,
			phone: resumeData.value.phone,
			email: resumeData.value.email,
			address: resumeData.value.address || null,
			educationHistory: JSON.stringify(resumeData.value.education),
			workExperience: JSON.stringify(resumeData.value.experience),
			skills: JSON.stringify(resumeData.value.skills),
			projects: JSON.stringify(resumeData.value.projects)
		};
		post('/resume/saveOrUpdate', requestData, content => {
		})
	} catch (error) {
		console.error('保存简历失败:', error);
		ElMessage.error('保存简历失败，请重试');
	}
};

// 获取过往记录
const getResumeRecord = async () => {
	try {
		// 发送请求到后端获取简历记录
		get('/resume/getByUserId', {}, content => {
			console.dir(content)
			if (content) {
				url.value = getFile(content.photoUrl)
				resumeData.value = {
					photo: getFile(content.photoUrl) || '',
					name: content.name || '',
					jobTarget: content.jobTarget || '',
					phone: content.phone || '',
					email: content.email || '',
					address: content.address || '',
					education: content.educationHistory ? JSON.parse(content.educationHistory) : [{ school: '', degree: '', major: '', period: '' }],
					experience: content.workExperience ? JSON.parse(content.workExperience) : [{ company: '', position: '', period: '', description: '' }],
					skills: content.skills ? JSON.parse(content.skills) : [{ name: '', level: '熟练' }],
					projects: content.projects ? JSON.parse(content.projects) : [{ name: '', role: '', period: '', description: '' }]
				}
			} else {
				ElMessage.warning('暂无过往记录');
			}
		})
	} catch (error) {
		console.error('获取过往记录失败:', error);
		ElMessage.error('获取过往记录失败，请重试');
	}
};

// 页面加载时尝试获取简历记录
onMounted(() => {
	// 可以在这里添加逻辑，决定是否自动获取记录
	// getResumeRecord();
});

const handlePhotoUpload = (event) => {
	const file = event.target.files[0];
	resumeData.value.file = file;
	if (file) {
		const reader = new FileReader();
		reader.onload = (e) => {
			url.value = e.target.result;
		};
		reader.readAsDataURL(file);
	}
};

const removePhoto = () => {
	resumeData.value.photo = '';
};

const addEducation = () => {
	resumeData.value.education.push({ school: '', degree: '', major: '', period: '' });
};

const removeEducation = (index) => {
	if (resumeData.value.education.length > 1) {
		resumeData.value.education.splice(index, 1);
	}
};

const addExperience = () => {
	resumeData.value.experience.push({ company: '', position: '', period: '', description: '' });
};

const removeExperience = (index) => {
	if (resumeData.value.experience.length > 1) {
		resumeData.value.experience.splice(index, 1);
	}
};

const addSkill = () => {
	resumeData.value.skills.push({ name: '', level: '熟练' });
};

const removeSkill = (index) => {
	if (resumeData.value.skills.length > 1) {
		resumeData.value.skills.splice(index, 1);
	}
};

const addProject = () => {
	resumeData.value.projects.push({ name: '', role: '', period: '', description: '' });
};

const removeProject = (index) => {
	if (resumeData.value.projects.length > 1) {
		resumeData.value.projects.splice(index, 1);
	}
};

const generateResume = () => {
	// 实时更新预览，无需额外操作
};

const resetForm = () => {
	resumeData.value = {
		photo: '',
		name: '',
		jobTarget: '',
		phone: '',
		email: '',
		address: '',
		education: [
			{ school: '', degree: '', major: '', period: '' }
		],
		experience: [
			{ company: '', position: '', period: '', description: '' }
		],
		skills: [
			{ name: '', level: '熟练' }
		],
		projects: [
			{ name: '', role: '', period: '', description: '' }
		]
	};
};

const formatDescription = (text) => {
	if (!text) return '';
	return text.replace(/\n/g, '<br>');
};

const getSkillLevelWidth = (level) => {
	switch(level) {
		case '精通': return '100%';
		case '熟练': return '75%';
		case '了解': return '50%';
		default: return '50%';
	}
};

const downloadResume = () => {
	const resumeElement = document.querySelector('.resume-preview');
	
	html2canvas(resumeElement).then(canvas => {
		const link = document.createElement('a');
		link.download = `${resumeData.value.name || '我的'}简历.png`;
		link.href = canvas.toDataURL('image/png');
		link.click();
	})
}

const printResume = () => {
	window.print();
}
</script>

<style scoped>
/* 专业配色方案 */
:root {
  --primary-color: #2c3e50;
  --secondary-color: #1a252f;
  --accent-color: #3498db;
  --light-color: #ecf0f1;
  --dark-color: #2c3e50;
  --gray-color: #7f8c8d;
  --border-color: #bdc3c7;
  --success-color: #27ae60;
  --danger-color: #e74c3c;
  --warning-color: #f39c12;
  --info-color: #2980b9;
  --text-color: #2c3e50;
  --bg-color: #ffffff;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --nested-card-bg: #f8f9fa;
}

/* 全局样式 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', 'Noto Sans SC', sans-serif;
}

body {
  background-color: #f5f7fa;
  color: var(--text-color);
  line-height: 1.6;
}

h1, h2, h3 {
  margin-bottom: 1rem;
  font-weight: 700;
  color: var(--dark-color);
}

/* 主容器 */
.resume-generator {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--primary-color);
}

.header h1 {
  font-size: 2.5rem;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.subtitle {
  font-size: 1.2rem;
  color: var(--gray-color);
  font-weight: 400;
}

.container {
  display: flex;
  gap: 2rem;
}

/* 卡片样式 */
.card {
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);
}

.nested-card {
  background: var(--nested-card-bg);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--primary-color);
}

/* 表单部分 */
.form-section {
  flex: 1;
  min-width: 0;
}

.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.form-header h2 {
  display: flex;
  align-items: center;
  font-size: 1.5rem;
  color: var(--dark-color);
}

.form-header h2 i {
  color: var(--primary-color);
  font-size: 1.2rem;
  margin-right: 0.5rem;
}

/* 已删除record-btn样式，获取过往记录按钮现在使用generate-btn样式 */


.form-group-header {
  display: flex;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--primary-color);
}

.form-group-header h3 {
  margin-left: 0.75rem;
  color: var(--primary-color);
  font-size: 1.25rem;
}

.form-group-header i {
  color: var(--accent-color);
  font-size: 1.1rem;
}

.form-content {
  padding: 0.5rem;
}

.form-row {
  margin-bottom: 1.25rem;
}

.form-row label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--dark-color);
  font-size: 0.95rem;
}

.form-row .required {
  color: var(--danger-color);
  margin-left: 0.2rem;
}

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.1);
}

.form-row textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.6;
}

/* 照片上传 */
.photo-upload {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.photo-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--light-color);
  color: var(--dark-color);
  border: 2px dashed var(--border-color);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.upload-btn:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.upload-btn i {
  margin-right: 0.5rem;
}

.photo-preview {
  position: relative;
  width: 120px;
  height: 160px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid var(--border-color);
}

.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-photo {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 28px;
  height: 28px;
  background: var(--danger-color);
  color: white;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

.remove-photo:hover {
  background: #c0392b;
}

.select-wrapper {
  position: relative;
}

.select-wrapper select {
  appearance: none;
  padding-right: 2.5rem;
}

.select-wrapper i {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--gray-color);
}

.remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger-color);
  color: rgb(255, 6, 6);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  margin-top: 0.5rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.remove-btn:hover {
  background: #c0392b;
  transform: translateY(-1px);
}

.remove-btn i {
  margin-right: 0.3rem;
  font-size: 0.8rem;
}

.add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-color);
  color: rgb(0, 0, 0);
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.add-btn:hover {
  background: var(--secondary-color);
  transform: translateY(-1px);
}

.add-btn i {
  margin-right: 0.4rem;
  font-size: 0.9rem;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2rem;
}

.generate-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--success-color);
  color: rgb(14, 39, 152);
  border: none;
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.generate-btn:hover {
  background: #219653;
  transform: translateY(-2px);
}

.reset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-color);
  color: rgb(217, 22, 22);
  border: none;
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: background 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.reset-btn:hover {
  background: #6c757d;
  transform: translateY(-2px);
}



.reset-btn i,
.generate-btn i {
  margin-right: 0.5rem;
}

/* 预览部分 */
.preview-section {
  flex: 0 0 45%;
  min-width: 0;
  position: sticky;
  top: 2rem;
  align-self: flex-start;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--primary-color);
}

.preview-header h2 {
  display: flex;
  align-items: center;
  font-size: 1.5rem;
  color: var(--dark-color);
}

.preview-header .icon {
  color: var(--primary-color);
  font-size: 1.2rem;
  margin-right: 0.5rem;
}

.preview-actions {
  display: flex;
  gap: 0.75rem;
}

.download-btn,
.print-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-color);
  color: rgb(0, 0, 0);
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.download-btn:hover,
.print-btn:hover {
  background: var(--secondary-color);
  transform: translateY(-1px);
}

.download-btn i,
.print-btn i {
  margin-right: 0.4rem;
}

.resume-preview {
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  padding: 2rem;
  border: 1px solid var(--border-color);
}

.resume-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--primary-color);
}

.name-title {
  flex: 1;
}

.name-title h1 {
  font-size: 2.2rem;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.job-target {
  font-size: 1.2rem;
  color: var(--gray-color);
  font-weight: 500;
}

.photo-container {
  width: 120px;
  height: 160px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid var(--border-color);
}

.photo-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.resume-body {
  padding-top: 0.5rem;
}

.resume-section {
  margin-bottom: 2rem;
}

.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary-color);
}

.section-header h2 {
  margin-left: 0.75rem;
  color: var(--primary-color);
  font-size: 1.4rem;
}

.section-header i {
  color: var(--primary-color);
  font-size: 1.2rem;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
}

.info-item i {
  color: var(--primary-color);
  width: 1.2rem;
  text-align: center;
  font-size: 1rem;
}

.education-list,
.experience-list,
.project-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.education-item,
.experience-item,
.project-item {
  margin-bottom: 1.5rem;
}

.edu-header,
.exp-header,
.project-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.edu-left,
.exp-left,
.project-left {
  flex: 1;
}

.edu-header h3,
.exp-header h3,
.project-header h3 {
  font-size: 1.1rem;
  color: var(--dark-color);
  margin-bottom: 0.25rem;
}

.degree-major,
.position,
.role {
  font-size: 0.9rem;
  color: var(--gray-color);
}

.period {
  font-size: 0.9rem;
  color: var(--primary-color);
  font-weight: 600;
  white-space: nowrap;
}

.description {
  line-height: 1.7;
  color: var(--dark-color);
  font-size: 0.95rem;
}

.skill-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.25rem;
}

.skill-item {
  display: flex;
  flex-direction: column;
}

.skill-name {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--dark-color);
}

.skill-level {
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  margin-bottom: 0.25rem;
  overflow: hidden;
}

.level-bar {
  height: 100%;
  background: var(--primary-color);
  border-radius: 4px;
}

.level-text {
  font-size: 0.8rem;
  color: var(--gray-color);
  text-align: right;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .container {
    flex-direction: column;
  }
  
  .preview-section {
    position: static;
    order: -1;
    margin-bottom: 2rem;
  }
  
  .info-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .resume-generator {
    padding: 1.5rem;
  }
  
  .header h1 {
    font-size: 2rem;
  }
  
  .resume-header {
    flex-direction: column;
    gap: 1.5rem;
  }
  
  .photo-container {
    margin-top: 1rem;
  }
  
  .skill-list {
    grid-template-columns: 1fr;
  }
  
  .actions {
    flex-direction: column;
  }
  
  .generate-btn,
   .reset-btn {
      width: 100%;
    }
    
    .form-header .record-btn {
      width: auto;
      margin-bottom: 1rem;
    }
}

@media print {
  .form-section,
  .preview-header,
  .header {
    display: none;
  }
  
  .resume-preview {
    box-shadow: none;
    padding: 0;
    margin: 0;
    border: none;
  }
  
  .container {
    display: block;
  }
}
</style>
